package com.feonix.common.log;

import javax.servlet.ServletContextEvent;

import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import org.springframework.web.util.Log4jConfigListener;

import com.feonix.common.util.LogUtil;

public class Log4jListener extends Log4jConfigListener {

	public void contextInitialized(ServletContextEvent paramServletContextEvent) {
		super.contextInitialized(paramServletContextEvent);
		((PatternLayout) Logger.getRootLogger().getAppender("stdout").getLayout()).setConversionPattern(
				"%d{yyyy-MM-dd HH:mm:ss} [" + paramServletContextEvent.getServletContext().getServletContextName()
						+ "] %5p %c{1}:%L - %m (FEONIX Co. Ltd.)%n");

		logSlowSql(paramServletContextEvent);
	}

	private void logSlowSql(ServletContextEvent servletContextEvent) {
		String logPath = servletContextEvent.getServletContext().getRealPath("") + "/WEB-INF/logs/slow_sql/sql";
		String contextName = servletContextEvent.getServletContext().getServletContextName();
		String str3 = "jdbc.sqltiming";
		String name = "slowsql";
		LogUtil.setLogLevel(str3, "warn", LogUtil.createDailyFileLog(name, logPath, contextName), false);
	}

}
